﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Caramel.ServiceBus
{
	public static class ServiceBusExtensions
	{
		public static void Send<T>(this IServiceBus bus, Action<T> constructor) where T : ICommand
		{
			var command = Activator.CreateInstance<T>();

			constructor(command);

			bus.Send(command);
		}

		public static void Publish<T>(this IServiceBus bus, Action<T> constructor) where T : IEvent
		{
			var @event = Activator.CreateInstance<T>();

			constructor(@event);

			bus.Publish(@event);
		}
	}
}
